package com.xuecheng.content.api.controller;

import com.xuecheng.content.model.dto.CoursePreviewDto;
import com.xuecheng.content.model.po.CoursePublish;
import com.xuecheng.content.services.service.CoursePublishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.math.raw.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author:王亚栋
 * @Date:2023/8/4 21:16
 * @Version:1.0
 */
@Controller
@Api(value = "课程发布接口",tags = "课程发布接口")
@Slf4j(topic = "CoursePublishController")
public class CoursePublishController {

    @Autowired
    private CoursePublishService coursePublishService;

    /**
     * 课程预览接口
     * @param courseId 课程Id
     * @return
     */
    @GetMapping("/coursepreview/{courseId}")
    public ModelAndView preview(@PathVariable("courseId") Long courseId){

        ModelAndView modelAndView = new ModelAndView();

        //查询课程的信息作为模型数据
        CoursePreviewDto coursePreviewInfo = coursePublishService.getCoursePreviewInfo(courseId);
        log.info("查询出来的数据:{}",coursePreviewInfo);

        modelAndView.addObject("model", coursePreviewInfo);

        modelAndView.setViewName("course_template");

        return modelAndView;

    }

    /**
     * 课程审核
     * @param courseId 课程Id
     */
    @ResponseBody
    @PostMapping("/courseaudit/commit/{courseId}")
    public void commitAudit(@PathVariable("courseId") Long courseId){

        Long companyId = 1232141425L;

        coursePublishService.commitAudit(companyId,courseId);
    }

    @ApiOperation("课程发布")
    @ResponseBody
    @PostMapping("/coursepublish/{courseId}")
    public void coursePublish(@PathVariable("courseId") Long courseId){


    }

    /**
     * 查询课程发布信息 以/r/打头的作为服务内部调用
     * @param courseId
     * @return
     */
    @ApiOperation("查询课程发布信息")
    @GetMapping("/r/coursepublish/{courseId}")
    @ResponseBody
    public CoursePublish getCoursePublish(@PathVariable("courseId") Long courseId){

       CoursePublish coursePublish =  coursePublishService.getCoursePublish(courseId);

       return coursePublish;
    }
}
